package com.threefire.quickstart;


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.io.UnsupportedEncodingException;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/12-17:21
 */
public class ClientHandler extends ChannelInboundHandlerAdapter {

    /**
     * channelActive
     * 激活方法
     * @param cx ChannelHandlerContext对象
     */
    @Override
    public void channelActive(ChannelHandlerContext cx) {
        System.err.println("Client Channel active...");
    }

    /**
     *
     */
    @Override
    public void channelRead(ChannelHandlerContext cx, Object msg) throws UnsupportedEncodingException {
        Response response = (Response) msg;
        System.err.println("Client " + response.getId() + "," + response.getName());

    }

    /**
     * 捕获异常方法
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable throwable) {
        ctx.fireExceptionCaught(throwable);
    }

}
